//
//  JZYWCDetViewController.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/10/28.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "JZYWCDetViewController.h"

@interface JZYWCDetViewController ()

@property (nonatomic,strong)NSDictionary *dic;
@property (weak, nonatomic) IBOutlet UILabel *labName;
@property (weak, nonatomic) IBOutlet UILabel *labPrice1;
@property (weak, nonatomic) IBOutlet UILabel *labPrice2;
@property (weak, nonatomic) IBOutlet UILabel *labOrderNum;
@property (weak, nonatomic) IBOutlet UILabel *labDate;
@property (weak, nonatomic) IBOutlet UILabel *labPayMent;
@property (weak, nonatomic) IBOutlet UILabel *labPSDZ;
@property (weak, nonatomic) IBOutlet UILabel *labPhone;
@property (weak, nonatomic) IBOutlet UILabel *labAddress;
@property (weak, nonatomic) IBOutlet UILabel *labReMARK;
@property (weak, nonatomic) IBOutlet UIView *starView;
@property (weak, nonatomic) IBOutlet UILabel *labPJ;

@end

@implementation JZYWCDetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self showNav:@"订单详情"];
    [self loadData];
    
}

- (void)loadUI{
    _labName.text = [_dic objectForKey:@"ordername"];
    _labPrice1.text = [NSString stringWithFormat:@"%@元/时",[_dic objectForKey:@"ordermoney"]];
    _labPrice2.text = [_dic objectForKey:@"ordermoney"];
    _labOrderNum.text = [_dic objectForKey:@"ordernumber"];
    NSString *addtime = [NSString stringWithFormat:@"%li",[[_dic objectForKey:@"addtime"] integerValue]];
    NSString *date = [self getNewDate:addtime];
    _labDate.text = date;
    NSString *payment = [NSString stringWithFormat:@"%li",[[_dic objectForKey:@"payment"] integerValue]];
    if ([payment integerValue] == 2) {
        _labPayMent.text = @"微信支付";
    }else if ([payment integerValue] == 3){
        _labPayMent.text = @"支付宝支付";
    }else if ([payment integerValue] == 4){
        _labPayMent.text = @"银联支付";
    }else if ([payment integerValue] == 5){
        _labPayMent.text = @"余额支付";
    }
    _labPSDZ.text = [_dic objectForKey:@"consignee"];
    _labPhone.text = [_dic objectForKey:@"phone"];
    _labAddress.text = [_dic objectForKey:@"address"];
    _labReMARK.text = [_dic objectForKey:@"remaek"];
    
    NSDictionary *comment = [_dic objectForKey:@"comment"];
    if ([comment isKindOfClass:[NSDictionary class]]) {
        StarView *star = [[StarView alloc] initWithFrame:CGRectMake(0, 0, 80, 16)];
        star.showStar = 0;
        [_starView addSubview:star];
        
        _labPJ.text = @"暂无用户评价";
    }else{
        StarView *star = [[StarView alloc] initWithFrame:CGRectMake(0, 0, 80, 16)];
        NSString *count = [[_dic objectForKey:@"comment"] objectForKey:@"star"];
        NSInteger index = [count integerValue];
        star.showStar = index * 20.0;
        [_starView addSubview:star];
        
        _labPJ.text = [[_dic objectForKey:@"comment"] objectForKey:@"comment"];
    }
    
}
//家政完成详情
- (void)loadData{
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:_orderId forKey:@"id"];
    [parmas setObject:_merid forKey:@"merchantid"];
    NSString *url = [NSString stringWithFormat:@"%@/App/Ordermanage/housekeepingdetails",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"家政完成详情res:%@",responseObject);
        NSString *error = [NSString stringWithFormat:@"%li",[[responseObject objectForKey:@"error"] integerValue]];
        if ([error integerValue] == 200) {
//            _array = [[responseObject objectForKey:@"result"] objectForKey:@"delivery"];
            _dic = [responseObject objectForKey:@"result"];
        }
        
        [self loadUI];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
